package com.pr.controller;

import com.pr.entity.CreateModel;
import com.pr.entity.Person;
import com.xw.framework.rest.AbstractBaseHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.util.Date;

/**
 * @description:
 * @projectName:SpringSkill
 * @see:org.pr.springskill
 * @author:LXC
 * @createTime:2024/4/22 10:20
 * @version:1.0
 */
@RestController
@RequestMapping("person")
public class PersonController extends AbstractBaseHandler {

    @RequestMapping("getPerson")
    public Person getPerson(){
        Person person = Person.Factory.make();
        person.setName("jack");
        person.setId("person1");
        person.setAddress("中国*广东");
        person.setBirthDay(new Date());
        System.out.println(person.getName());
        person.savePerson();
        return person;
    }

    @RequestMapping("getPersonInfo")
    public Person getPersonInfo(@Valid @RequestBody Mono<CreateModel> modelMono){

        Person person = Person.Factory.make();
        person.setName("jack");
        person.setId("person1");
        person.setAddress("中国*广东");
        person.setBirthDay(new Date());
        System.out.println(person.getName());
        person.savePerson();
        modelMono.flatMap(v->{
            person.setName(v.getName());
            return null;
        });
        return person;
    }
}
